package com.ssy.lingxi.logistics.controller;

import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.model.dto.UserLoginCacheDTO;
import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.logistics.api.dto.request.CommonIdRequest;
import com.ssy.lingxi.logistics.model.request.CommonStatusRequest;
import com.ssy.lingxi.logistics.model.request.FreightTemplateListRequest;
import com.ssy.lingxi.logistics.model.request.FreightTemplateRequest;
import com.ssy.lingxi.logistics.model.request.OrderProductListRequest;
import com.ssy.lingxi.logistics.model.response.FreightTemplateListResponse;
import com.ssy.lingxi.logistics.model.response.FreightTemplateResponse;
import com.ssy.lingxi.logistics.service.IFreightTemplateService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * @menu 物流能力 - 物流管理 - 运费模板管理
 * @author yzc
 * @version 2.0.0
 * @date 2020/7/14
 */
@RestController
@RequestMapping("/logistics/freightTemplate")
public class FreightTemplateController extends BaseController {

    @Resource
    private IFreightTemplateService freightTemplateService;

    /**
     * 运费模板分页列表
     * @param request 接口参数
     * @return 返回结果
     */
    @GetMapping("/page")
    public Wrapper<PageData<FreightTemplateListResponse>> pageFreightTemplate(FreightTemplateListRequest request) {
        UserLoginCacheDTO sysUser = getSysUser();
        return freightTemplateService.pageFreightTemplate(request, sysUser);
    }

    /**
     * 运费模板查询
     * @param id 主键id
     * @return 返回结果
     */
    @GetMapping(value = "/get")
    public Wrapper<FreightTemplateResponse> getFreightTemplate(@RequestParam(name = "id") Long id) {
        return freightTemplateService.getFreightTemplate(id);
    }

    /**
     * 运费模板添加
     * @param request 接口参数
     * @return 返回结果
     */
    @PostMapping(value = "/add")
    public Wrapper<Void> addFreightTemplate(@RequestBody @Validated(FreightTemplateRequest.Add.class) FreightTemplateRequest request) {
        UserLoginCacheDTO sysUser = getSysUser();
        return freightTemplateService.addFreightTemplate(request, sysUser);
    }

    /**
     * 运费模板修改
     * @param request 接口参数
     * @return 返回结果
     */
    @PostMapping(value = "/update")
    public Wrapper<Void> updateFreightTemplate(@RequestBody @Validated(FreightTemplateRequest.Update.class) FreightTemplateRequest request) {
        UserLoginCacheDTO sysUser = getSysUser();
        return freightTemplateService.updateFreightTemplate(request, sysUser);
    }

    /**
     * 运费模板停用/启用
     * @param request 接口参数
     * @return 返回结果
     */
    @PostMapping(value = "/enable")
    public Wrapper<Void> updateStatusFreightTemplate(@RequestBody @Validated CommonStatusRequest request) {
        UserLoginCacheDTO sysUser = getSysUser();
        return freightTemplateService.updateStatusFreightTemplate(request, sysUser);
    }

    /**
     * 运费模板删除
     * @param request 接口参数
     * @return 返回结果
     */
    @PostMapping(value = "/delete")
    public Wrapper<Void> deleteFreightTemplate(@RequestBody @Validated CommonIdRequest request) {
        UserLoginCacheDTO sysUser = getSysUser();
        return freightTemplateService.deleteFreightTemplate(request, sysUser);
    }

    /**
     * 运费计算
     * @param request 接口参数
     * @return 返回结果
     */
    @PostMapping(value = "/calFreightPrice")
    public Wrapper<BigDecimal> calFreightPrice(@RequestBody @Validated OrderProductListRequest request) {
        return freightTemplateService.calFreightPrice(request);
    }

}
